package com.chukun.thrift.dev;

import com.chukun.thrift.Person;
import com.chukun.thrift.ThriftPersonService;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;

public class ThriftPersonServiceClient {

    public static void main(String[] args) {
        TTransport tTransport = new TFramedTransport(new TSocket("localhost",8899),600);
        TProtocol protocol = new TCompactProtocol(tTransport);
        ThriftPersonService.Client client = new ThriftPersonService.Client(protocol);

        try{
            tTransport.open();
            Person person = client.findPersonByUserName("tom");
            System.out.println(person.getUserName());
            System.out.println(person.getAge());
            System.out.println(person.isMarried());

            client.savePerson(person);
        }catch (Exception e){
            throw  new RuntimeException(e.getMessage(),e);
        }finally {
            tTransport.close();
        }
    }
}
